using System;
using System.Collections.Generic;
using System.Text;

namespace Skywave.ComponentModel
{
    public static class ByteArrayConverter
    {
        public static string ToString(byte[] input)
        {
            string r = "";
            foreach (byte b in input)
            {
                r += b.ToString("000");
            }
            return r;
        }
        public static byte[] FromString(string input)
        {
            if ((input.Length % 3) != 0)
            {
                throw new ArgumentException("String Length must be a multiple of 3.");
            }
            string tmp;
            byte[] r;
            System.Collections.ArrayList al = new System.Collections.ArrayList();
            while (input.Length > 0)
            {
                tmp = input.Substring(0, 3);
                input = input.Remove(0, 3);
                al.Add(byte.Parse(tmp));
            }
            r = new byte[al.Count];
            for (int i = 0; i < al.Count; i++)
            {
                r[i] = (byte)al[i];
            }
            return r;
        }
    }
}
